/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package control;

import com.opensymphony.xwork2.ActionSupport;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts2.ServletActionContext;

import java.util.List;
import java.util.Date;
import service.IItemService;
import pojo.Item;

/**
 *
 * @author administrator
 */
public class ItemActionAdmin extends ActionSupport{
    private IItemService<Item> itemService;
    private String name;
    private String description;
    private int price;
    private int amount;
    private String path;
    private int id;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public IItemService<Item> getItemService() {
        return itemService;
    }

    public void setItemService(IItemService<Item> itemService) {
        this.itemService = itemService;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public int getPrice() {
        return price;
    }

    public void setPrice(int price) {
        this.price = price;
    }

    public String save()
    {
        Item item = new Item();
        if(this.amount< 0 || this.price < 0)
            return "error";
        item.setItemAmount(this.amount);
        item.setItemPrice(this.price);
        item.setItemDescription(this.description);
        item.setItemImagePath(this.path);
        //item.setItemId(this.id);
        item.setItemName(this.name);
        this.itemService.save(item);
        return "main";
    }

}
